how to handle error in javascript